<template>
	<view>
		<view v-if="token">
			<view class="withdrawal z-padding-32 z-margin-t-48">
				<view class="tx-text">提现金额</view>
				<view class="input-box z-margin-t-24 z-padding-lr-32">
					￥
					<input class="z-margin-l-24" placeholder="输入提现金额" type="digit" v-model="num"/>
				</view>
				<view class="z-flex-c-s-b z-margin-t-24">
					<view class="can-tx">可提现余额：{{ money }}</view>
					<view class="all-tx" @tap="all">全部提现</view>
				</view>
			</view>

			<view class="title">选择提现账户</view>

			<view class="way z-padding-32 z-margin-t-24 z-flex-c-s-b" @tap="AlipayWay">
				<view class="way-flex">
					<image src="../../static/service/Alipay.png" class="bank-img"></image>
					<view class="z-margin-l-24">
						<view class="way-title">提现至支付宝</view>
						<view class="way-text z-margin-t-16" @tap.stop="tobindAccount(0)" v-if="info.alipay_name && info.alipay_account">
							{{ info.alipay_name }} {{ info.alipay_account }}
							<image class="next-r" src="../../static/service/r-img.png"></image>
						</view>
						<view class="way-text z-margin-t-16" @tap="tobindAccount(0)" v-else>
							请设置提现账户
							<image class="next-r" src="../../static/service/r-img.png"></image>
						</view>
					</view>
				</view>
				<image :src="txWay == 0 ? '../../static/service/checkbox.png' : '../../static/service/check.png'" class="check-img"></image>
			</view>

			<view class="way z-padding-32 z-margin-t-24 z-flex-c-s-b" @tap="bankWay">
				<view class="way-flex">
					<image src="../../static/service/bank-card.png" class="bank-img"></image>
					<view class="z-margin-l-24">
						<view class="way-title">提现至银行卡</view>
						<view class="way-text z-margin-t-16" @tap.stop="tobindAccount(1)" v-if="info.bank_user && info.bank_name && info.bank_card">
							{{ info.bank_user }} {{ info.bank_card }}
							<image class="next-r" src="../../static/service/r-img.png"></image>
						</view>
						<view class="way-text z-margin-t-16" @tap.stop="tobindAccount(1)" v-else>
							请设置提现账户
							<image class="next-r" src="../../static/service/r-img.png"></image>
						</view>
					</view>
				</view>
				<image :src="txWay == 1 ? '../../static/service/checkbox.png' : '../../static/service/check.png'" class="check-img"></image>
			</view>

			<view v-if="type == 1" class="text_999 z-font-22 z-padding-32">温馨提示：商家设置每{{ day }}可提现</view>
			<view class="bzj-text z-flex z-font-28 z-margin-t-40" @tap="clickread">
				<image src="../../static/service/check.png" v-if="!agree" class="choose_img z-margin-r-8" mode="" />
				<image src="../../static/service/checkbox.png" v-else class="choose_img z-margin-r-8" mode="" />
				已阅读并同意
				<text class="theme-color" @tap="infoTap()">《提现协议》</text>
			</view>
			<view class="z-btn z-margin-t-72 z-margin-lr-32" @tap="withdraw">提交</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			agree: false,
			txWay: 0,
			info: '',
			money: '',
			type: '',
			num: '',
			other: '',
			day: '',
			token: ''
		};
	},
	onLoad(options) {
		this.type = options.type,
		this.token = uni.getStorageSync('token')
	},
	onShow() {
		this.getInfo();
	},
	methods: {
		clickread() {
			this.agree = !this.agree
		},
		tobindAccount(e) {
			uni.navigateTo({
				url: '/service/bindAccount/bindAccount?account=' + e
			});
		},
		bankWay() {
			this.txWay = 1
		},
		all() {
			this.num = this.money
		},
		AlipayWay() {
			this.txWay = 0
		},
		infoTap() {
			let id = uni.getStorageSync('config').withdraw_info_id;
			this.util.skip('/service/info/info?id=' + id + '&name=提现协议');
		},
		withdraw() {
			if (!this.agree) {
				this.util.toast('请先阅读并同意《提现协议》');
				return;
			}
			if (Number(this.num) <= 0) return this.util.toast('请输入正确的金额');
			if (Number(this.num) > Number(this.money)) return this.util.toast('提现金额不能大于' + this.money);
			if (this.txWay == 0 && (!this.info.alipay_name || !this.info.alipay_account)) return this.util.toast('请绑定支付宝账户');
			if (this.txWay == 1 && (!this.info.bank_user || !this.info.bank_name || !this.info.bank_card)) return this.util.toast('请绑定银行卡账户信息');
			this.http.post(
				'withdraw/apply',
				{
					withdrawtype: this.txWay,
					type: this.type,
					num: this.num,
					types: 'withdraw'
				},
				true,
				false
			)
				.then((res) => {
					this.util.toast(res.msg);
					setTimeout(() => {
						this.getInfo();
					}, 1000);
				})
				.catch((e) => {
					let data = e.data;
					this.util.toast(data.data);
				});
		},
		getInfo() {
			this.http.get('index/updateuser').then((res) => {
				this.info = res.data
				if (this.type == 1) {
					this.info = res.data,
					this.money = res.data.shop_money
				} else if (this.type == 2) {
					this.info = res.data,
					this.money = res.data.shop_user_money
				} else if (this.type == 3) {
					this.info = res.data,
					this.money = res.data.skillEnsurePrice
				} else if (this.type == 4) {
					this.info = res.data,
					this.money = res.data.shopEnsurePrice
				} else {
					this.info = res.data,
					this.money = res.data.money
				}
			});

			if (this.type == 1) {
				this.http.get('withdraw/getwithdrawday', {
					type: 1
				}).then((res) => {
					let week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
					let arr = [];
					for (let i = 1; i < 29; i++) {
						arr.push('月' + i + '号');
					}
					this.other = res.data,
					this.day = res.data.withdrawtype == 1 ? week[res.data.day] : arr[res.data.day - 1]
				});
			}
		}
	}
};
</script>

<style>
page {
	background-color: #edf1f4;
}
.withdrawal {
	width: 622rpx;
	height: 213rpx;
	background: #ffffff;
	border-radius: 20rpx 20rpx 20rpx 20rpx;
	opacity: 1;
	margin: auto;
}
.tx-text {
	font-size: 30rpx;
	font-weight: 500;
	color: #1c274c;
}
.input-box {
	width: 558rpx;
	height: 100rpx;
	background: #f5f7f9;
	border-radius: 20rpx 20rpx 20rpx 20rpx;
	opacity: 1;
	margin: auto;
	display: flex;
	align-items: center;
}
.can-tx {
	font-size: 22rpx;
	font-weight: 500;
	color: #6b738b;
}
.all-tx {
	font-size: 22rpx;
	font-weight: 500;
	color: #1677ff;
}
.title {
	font-size: 30rpx;
	font-weight: bold;
	color: #1c274c;
	margin: 40rpx 0 0 32rpx;
}
.way {
	width: 622rpx;
	height: 88rpx;
	background: #ffffff;
	border-radius: 20rpx 20rpx 20rpx 20rpx;
	opacity: 1;
	margin: auto;
}

.check-img {
	width: 32rpx;
	height: 32rpx;
}
.bank-img {
	width: 40rpx;
	height: 40rpx;
}
.way-flex {
	display: flex;
	align-items: center;
}
.way-title {
	font-size: 30rpx;
	font-weight: 500;
	color: #1c274c;
}
.way-text {
	font-size: 22rpx;
	font-weight: 500;
	color: #a4a9b7;
}
.next-r {
	width: 22rpx;
	height: 22rpx;
	vertical-align: middle;
}

.bzj-text {
	font-weight: 500;
	color: #a4a9b7;
}
.choose_img {
	width: 30rpx;
	height: 30rpx;
}
</style>
